import { defineStore } from "pinia";
import { getItem, setItem, updateItem } from "@/utils/localStorage";

const useUserStore = defineStore("userStore", {
  state: () => {
    return {
      // 用户信息
      userInfo: null,
      // token令牌
      token: undefined,
      // 导航选项列表（配置）
      navOptionList: [
        {
          id: 1,
          title: "把Applet推荐给好友",
          icon: "icon-saoma",
          page: "",
        },
        {
          id: 2,
          title: "设置",
          icon: "icon-shujutongji",
          page: "/pagesC/setting/index",
        },
        {
          id: 3,
          title: "意见反馈",
          icon: "icon-jiankang",
          page: "",
        },
        {
          id: 4,
          title: "联系官方",
          icon: "icon-kefu",
          page: "",
        },
      ],
    };
  },
  actions: {
    // 更新用户信息
    updateUserInfo(token, data, AllNumber) {
      this.token = token;
      this.userInfo = data;

      setItem("token", token);
      setItem("userInfo", data);

      // console.log("AllNumber", AllNumber);

      // updateItem("userInfo", "likeNumber", AllNumber.likeNumber);
      // updateItem("userInfo", "collectNumber", AllNumber.collectNumber);
      updateItem("userInfo", "viewHistory", data.historyNumber);
    },
  },
  getters: {},
});

export default useUserStore;
